package com.wrs.examsystem.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wrs.examsystem.entity.Result.R;
import com.wrs.examsystem.entity.Student;
import com.wrs.examsystem.entity.Teacher;
import com.wrs.examsystem.service.TeacherService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王荣升
 * @since 2024-05-15
 */
@RestController
@RequestMapping("/examsystem/teacher")
public class TeacherController {

    @Resource
    TeacherService teacherService;

    /**
     * 查询所有老师
     * 要进行脱敏处理
     * @return 返回所有老师
     */
    @GetMapping("findTeachers")
    public R findTeachers(){
        return teacherService.findTeachers();
    }

    /**
     * 根据教师编号查询教师信息
     * @param teacherNumber
     * @return
     */
    @GetMapping("findByTeacherNumber")
    public R findByTeacherNumber(@RequestParam("teacherNumber") String teacherNumber){
        String CHECK_TEACHER_NUMBER ="^\\d{5,}$";
        if (!teacherNumber.matches(CHECK_TEACHER_NUMBER)){
            return R.error().message("教师编号不合法");
        }
        return teacherService.findByTeacherNumber(teacherNumber);
    }

    /**
     * 根据教师编号删除教师
     * @param teacherNumber
     * @return
     */
    @DeleteMapping("deleteByTeacherNumber")
    public R deleteByTeacherNumber(@RequestParam("teacherNumber") String teacherNumber){
        String CHECK_TEACHER_NUMBER ="^\\d{5,}$";
        if (!teacherNumber.matches(CHECK_TEACHER_NUMBER)){
            return R.error().message("教师编号不合法");
        }
        return teacherService.deleteByTeacherNumber(teacherNumber);
    }
    /**
     * 核验
     * @param teacher
     * @return
     */
    @PostMapping("checkUser")
    public R checkUser(@RequestBody Teacher teacher){
        return teacherService.checkUser(teacher);
    }


}

